package org.jivesoftware.smack.provider;

import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;

public class ProviderManager
{
  private static ProviderManager instance;
  private Map<String, Object> extensionProviders = new ConcurrentHashMap();
  private Map<String, Object> iqProviders = new ConcurrentHashMap();

  public static synchronized ProviderManager getInstance()
  {
    if (instance == null)
      instance = new ProviderManager();
    return instance;
  }

  public static synchronized void setInstance(ProviderManager paramProviderManager)
  {
    if (instance != null)
      throw new IllegalStateException("ProviderManager singleton already set");
    instance = paramProviderManager;
  }

  protected void initialize()
  {
    try
    {
      ClassLoader[] arrayOfClassLoader1 = getClassLoaders();
      for (ClassLoader localClassLoader : arrayOfClassLoader1)
      {
        Enumeration localEnumeration = localClassLoader.getResources("META-INF/smack.providers");
        while (localEnumeration.hasMoreElements())
        {
          URL localURL = (URL)localEnumeration.nextElement();
          InputStream localInputStream = null;
          try
          {
            localInputStream = localURL.openStream();
            XmlPullParser localXmlPullParser = XmlPullParserFactory.newInstance().newPullParser();
            localXmlPullParser.setFeature("http://xmlpull.org/v1/doc/features.html#process-namespaces", true);
            localXmlPullParser.setInput(localInputStream, "UTF-8");
            int k = localXmlPullParser.getEventType();
            do
            {
              if (k == 2)
              {
                String str1;
                String str2;
                String str3;
                String str4;
                if (localXmlPullParser.getName().equals("iqProvider"))
                {
                  localXmlPullParser.next();
                  localXmlPullParser.next();
                  str1 = localXmlPullParser.nextText();
                  localXmlPullParser.next();
                  localXmlPullParser.next();
                  str2 = localXmlPullParser.nextText();
                  localXmlPullParser.next();
                  localXmlPullParser.next();
                  str3 = localXmlPullParser.nextText();
                  str4 = getProviderKey(str1, str2);
                  if (!this.iqProviders.containsKey(str4))
                    try
                    {
                      Class localClass1 = Class.forName(str3);
                      if (IQProvider.class.isAssignableFrom(localClass1))
                        this.iqProviders.put(str4, localClass1.newInstance());
                      else if (IQ.class.isAssignableFrom(localClass1))
                        this.iqProviders.put(str4, localClass1);
                    }
                    catch (ClassNotFoundException localClassNotFoundException1)
                    {
                      localClassNotFoundException1.printStackTrace();
                    }
                }
                else if (localXmlPullParser.getName().equals("extensionProvider"))
                {
                  localXmlPullParser.next();
                  localXmlPullParser.next();
                  str1 = localXmlPullParser.nextText();
                  localXmlPullParser.next();
                  localXmlPullParser.next();
                  str2 = localXmlPullParser.nextText();
                  localXmlPullParser.next();
                  localXmlPullParser.next();
                  str3 = localXmlPullParser.nextText();
                  str4 = getProviderKey(str1, str2);
                  if (!this.extensionProviders.containsKey(str4))
                    try
                    {
                      Class localClass2 = Class.forName(str3);
                      if (PacketExtensionProvider.class.isAssignableFrom(localClass2))
                        this.extensionProviders.put(str4, localClass2.newInstance());
                      else if (PacketExtension.class.isAssignableFrom(localClass2))
                        this.extensionProviders.put(str4, localClass2);
                    }
                    catch (ClassNotFoundException localClassNotFoundException2)
                    {
                      localClassNotFoundException2.printStackTrace();
                    }
                }
              }
              k = localXmlPullParser.next();
            }
            while (k != 1);
          }
          finally
          {
            try
            {
              localInputStream.close();
            }
            catch (Exception localException2)
            {
            }
          }
        }
      }
    }
    catch (Exception localException1)
    {
      localException1.printStackTrace();
    }
  }

  public Object getIQProvider(String paramString1, String paramString2)
  {
    String str = getProviderKey(paramString1, paramString2);
    return this.iqProviders.get(str);
  }

  public Collection<Object> getIQProviders()
  {
    return Collections.unmodifiableCollection(this.iqProviders.values());
  }

  public void addIQProvider(String paramString1, String paramString2, Object paramObject)
  {
    if ((!(paramObject instanceof IQProvider)) && ((!(paramObject instanceof Class)) || (!IQ.class.isAssignableFrom((Class)paramObject))))
      throw new IllegalArgumentException("Provider must be an IQProvider or a Class instance.");
    String str = getProviderKey(paramString1, paramString2);
    this.iqProviders.put(str, paramObject);
  }

  public void removeIQProvider(String paramString1, String paramString2)
  {
    String str = getProviderKey(paramString1, paramString2);
    this.iqProviders.remove(str);
  }

  public Object getExtensionProvider(String paramString1, String paramString2)
  {
    String str = getProviderKey(paramString1, paramString2);
    return this.extensionProviders.get(str);
  }

  public void addExtensionProvider(String paramString1, String paramString2, Object paramObject)
  {
    if ((!(paramObject instanceof PacketExtensionProvider)) && (!(paramObject instanceof Class)))
      throw new IllegalArgumentException("Provider must be a PacketExtensionProvider or a Class instance.");
    String str = getProviderKey(paramString1, paramString2);
    this.extensionProviders.put(str, paramObject);
  }

  public void removeExtensionProvider(String paramString1, String paramString2)
  {
    String str = getProviderKey(paramString1, paramString2);
    this.extensionProviders.remove(str);
  }

  public Collection<Object> getExtensionProviders()
  {
    return Collections.unmodifiableCollection(this.extensionProviders.values());
  }

  private String getProviderKey(String paramString1, String paramString2)
  {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("<").append(paramString1).append("/><").append(paramString2).append("/>");
    return localStringBuilder.toString();
  }

  private ClassLoader[] getClassLoaders()
  {
    ClassLoader[] arrayOfClassLoader1 = new ClassLoader[2];
    arrayOfClassLoader1[0] = ProviderManager.class.getClassLoader();
    arrayOfClassLoader1[1] = Thread.currentThread().getContextClassLoader();
    ArrayList localArrayList = new ArrayList();
    for (ClassLoader localClassLoader : arrayOfClassLoader1)
      if (localClassLoader != null)
        localArrayList.add(localClassLoader);
    return (ClassLoader[])localArrayList.toArray(new ClassLoader[localArrayList.size()]);
  }

  private ProviderManager()
  {
    initialize();
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.jivesoftware.smack.provider.ProviderManager
 * JD-Core Version:    0.6.1
 */